import java.awt.*;
import java.util.*;

public class NoobFish extends Fish {

    public NoobFish(Environment env, Location loc)
    {
        super(env, loc);
    }
    
    public NoobFish(Environment env, Location loc, Direction dir)
    {
        super(env, loc, dir);
    }
    
    public NoobFish(Environment env, Location loc, Direction dir, Color col)
    {
        super(env, loc, dir, col);
    }
    
    protected void move() {
        Location nextLoc = nextLocation();

        if ( ! nextLoc.equals(location()) ) {
            changeLocation(nextLoc);
        }
    }
    
    protected Location nextLocation() {
        Location newLoc = environment().getNeighbor(location(), direction().reverse());
        Random gen = new Random();
        int turn = 0;
        Direction randomDirection = null;
        
        if (environment().isValid(newLoc) && environment().isEmpty(newLoc)) {
            return newLoc;
        } else {
            turn = gen.nextInt(2);
            switch (turn) {
                case 0:
                    randomDirection = direction().toLeft();
                    break;
                case 1:
                    randomDirection = direction().toRight();
                    break;
            }
            newLoc = environment().getNeighbor(location(), randomDirection);
            changeDirection(randomDirection.reverse());
            if (environment().isValid(newLoc) && environment().isEmpty(newLoc)) {
                return newLoc;
            } else {
                return location();
            }
        }
    }
    
    public boolean breed() {
        return false;
    }
    
    public void die() {}
    
    private Color Color() {
        return new Color(255, 0, 0);
    }
}
